package com.opensso.core.interceptor;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by lixin on 2018/6/23.
 */
@SpringBootConfiguration
public class ContextConfiguration extends WebMvcConfigurerAdapter {


    @Bean
    public ContextInterceptor contextInterceptor() {
        return new ContextInterceptor();
    }

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Bean
    public DomainInterceptor domainInterceptor() {
        return new DomainInterceptor();
    }

    @Bean
    public VerifyInterceptor verifyInterceptor() {
        return new VerifyInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(contextInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**");//全局拦截器

        registry.addInterceptor(domainInterceptor())
                .addPathPatterns("/domain**")
                .excludePathPatterns("/swagger-resources/**");//域名拦截器

        registry.addInterceptor(verifyInterceptor())
                .addPathPatterns("/verify/**");//域名进行验证拦截器

//        registry.addInterceptor(loginInterceptor())
//                .addPathPatterns("/**")
//                .excludePathPatterns("/swagger-resources/**");//登录拦截器
    }
}
